/**
 @file ctc_asw_chip.h

 @author  Copyright (C) 2011 Centec Networks Inc.  All rights reserved.

 @date 2020-09-20

 @version v2.0

 This module is deal with chip's info, and peripheral device interface
 \p
 1)chip configuration
 \p
 The most important interface for chip initialization is datapath init, which will be provided here.
  \p
 2)MDIO interface
  \p
 These interfaces are used to manage phy devices. If you want to monitor special register in Phy, use another function for auto scan,
 you must set phy/mdio and port mapping relation correctly.
  \p
 3)Mac Led interface
  \p
 Before using mac led function, you must set mac sequence correctly.
  \p
*/

#ifndef _CTC_ASW_CHIP_H
#define _CTC_ASW_CHIP_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "ctc_chip.h"
/****************************************************************
*
* Defines and Macros
*
****************************************************************/
#define CTC_ASW_INVALID_PHY_SHIM_IDX 0xFF
/****************************************************************************
 *
* Function
*
*****************************************************************************/
/**
 @defgroup chip CHIP
 @{
*/

/**
 @brief Initialize the chip module and set the local chip number of the linecard

 @param[in] lchip    local chip id

 @param[in] lchip_num may be 1 or 2

 @remark[TMA]   Chip module init interface

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_init(uint8 lchip, uint8 lchip_num);

/**
 @brief De-Initialize chip module

 @param[in] lchip    local chip id

 @remark[TMA]  User can de-initialize the chip configuration

 @return CTC_E_XXX
*/
extern int32
ctc_asw_chip_deinit(uint8 lchip);

/**
 @brief The function is to set chip's global cnfig

 @param[in] lchip    local chip id

 @param[in] chip_cfg chip's global config

 @remark[TMA]   To Set chip module global configution

 @return CTC_E_XXX

*/
extern int32
ctc_asw_set_chip_global_cfg(uint8 lchip, ctc_chip_global_cfg_t* chip_cfg);

/**
 @brief The function is to get chip's clock

 @param[in] lchip    local chip id

 @param[out] freq frequency of the chip

 @remark[TMA]   To Get chip module clock

 @return CTC_E_XXX
*/
extern int32
ctc_asw_get_chip_clock(uint8 lchip, uint16* freq);

/**
 @brief set mac led parameter

 @param[in] lchip    local chip id

 @param[in] p_led_para mac led parameter

 @param[in] led_type  using one led or two leds

 @remark[TMA]   To set mac led parameter
  \p
                      to set led mode, set CTC_CHIP_LED_MODE_SET_OP in op_flag
  \p
                      to set led porality, set CTC_CHIP_LED_POLARITY_SET_OP in op_flag
  \p

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_set_mac_led_mode(uint8 lchip, ctc_chip_led_para_t* p_led_para, ctc_chip_mac_led_type_t led_type);

/**
 @brief set mac led mapping

 @param[in] lchip    local chip id

 @param[in] p_led_map mac sequence mapping for led

 @remark[TMA]   To set mac led mapping
 \p
                     Notice:the mapping must config correctly according hardware
                     the led control signal is genrated serially by chip, so must confirm the mac in the sequence driver
                     according led, also p_mac_id parameter must be allocated enough size according mac_led_num parameter

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_set_mac_led_mapping(uint8 lchip, ctc_chip_mac_led_mapping_t* p_led_map);

/**
 @brief set mac led enable

 @param[in] lchip    local chip id

 @param[in] enable enable mac led function

 @remark[TMA]   To set mac led enable.The interface just set mac led on chip0.If want to set mac led on other chip, please
                using interface :ctc_chip_set_property

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_set_mac_led_en(uint8 lchip, bool enable);

/**
 @brief The function is mdio interface to read phy

 @param[in] lchip_id    local chip id

 @param[in] type phy type to be access, Ge phy or Xg phy

 @param[in] p_para phy parameter

 @remark[TMA]   this interface is used for access phy using mdio parameter, if you want to access phy by GPORT parameter,
                please using the interface:ctc_chip_read_xgphy_reg/ctc_chip_read_gephy_reg

 @return CTC_E_XXX
*/
extern int32
ctc_asw_chip_mdio_read(uint8 lchip_id, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para);

/**
 @brief The function is mdio interface to write phy

 @param[in] lchip_id    local chip id

 @param[in] type phy type to be access, Ge phy or Xg phy

 @param[in] p_para phy parameter

 @remark[TMA]   this interface is used for access phy using mdio parameter, if you want to access phy by GPORT parameter,
                please using the interface:ctc_chip_write_gephy_reg/ctc_chip_write_xgphy_reg

 @return CTC_E_XXX
*/
extern int32
ctc_asw_chip_mdio_write(uint8 lchip_id, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para);

/**
 @brief set gpio interface

 @param[in] lchip    local chip id

 @param[in] gpio_id which gpio should be configured 

 @param[in] mode gpio mode to set

 @remark[TMA]   To set set gpio interface

 @return CTC_E_XXX.

*/
extern int32
ctc_asw_chip_set_gpio_mode(uint8 lchip, uint8 gpio_id, ctc_chip_gpio_mode_t mode);

/**
 @brief set gpio output value

 @param[in] lchip    local chip id

 @param[in] gpio_id which gpio should be configured

 @param[in]  out_para this para is only used in output mode, it control the output is high or low.

 @remark[TMA]   To set gpio output value

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_set_gpio_output(uint8 lchip, uint8 gpio_id, uint8 out_para);

/**
 @brief get gpio input value

 @param[in] lchip    local chip id

 @param[in] gpio_id which gpio should be configured

 @param[out]  in_value this para is only used in input mode, it indicate the input is high or low

 @remark[TMA]   To get gpio input value

 @return CTC_E_XXX

*/
extern int32
ctc_asw_chip_get_gpio_input(uint8 lchip, uint8 gpio_id, uint8* in_value);

/**
 @brief set chip property

 @param[in] lchip_id    local chip id

 @param[in] chip_prop chip property enum, refer to ctc_chip_property_t

 @param[in] p_value chip property value to set

 @remark[TMA] set chip property

 @return CTC_E_XXX
*/
extern int32
ctc_asw_chip_set_property(uint8 lchip_id,  ctc_chip_property_t chip_prop,  void* p_value);

/**
 @brief get chip property

 @param[in] lchip_id    local chip id

 @param[in] chip_prop chip property enum, refer to ctc_chip_property_t

 @param[out] p_value chip property get value

 @remark[TMA] get chip property

 @return CTC_E_XXX
*/
extern int32
ctc_asw_chip_get_property(uint8 lchip_id,  ctc_chip_property_t chip_prop,  void* p_value);

/**
 @brief The function is to init datapath

 @param[in] lchip_id    local chip id

 @param[in] p_global_cfg datapath serdes config and core clock

 @remark[TMA]   Init Datapath

 @return CTC_E_XXX
*/
extern int32
ctc_asw_datapath_init(uint8 lchip_id, void* p_global_cfg);

INTERNAL int32
_ctc_chip_serdes_read(uint8 lchip, uint8 serdes_id, uint32 address, uint16* p_value16);
INTERNAL int32
_ctc_chip_serdes_write(uint8 lchip, uint8 serdes_id, uint32 address, uint16 value16);
INTERNAL int32
_ctc_asw_datapath_get_link_up(uint8 lchip, uint32 gport, uint32* p_value);
INTERNAL int32
_ctc_asw_datapath_set_pcs_en(uint8 lchip, uint32 gport, uint32 value);
INTERNAL int32
_ctc_asw_datapath_set_auto_neg_mode(uint8 lchip, uint32 gport, ctc_port_auto_neg_mode_t auto_neg_mode);
INTERNAL int32
_ctc_asw_datapath_get_auto_neg_mode(uint8 lchip, uint32 gport, ctc_port_auto_neg_mode_t* p_auto_neg_mode);
INTERNAL int32
_ctc_asw_datapath_set_auto_neg_enable(uint8 lchip, uint32 gport, uint32 enable);
INTERNAL int32
_ctc_asw_datapath_get_auto_neg_enable(uint8 lchip, uint32 gport, uint32* p_enable);
INTERNAL int32
_ctc_asw_datapath_set_unidir_en(uint8 lchip, uint32 gport, uint32 enable);
INTERNAL int32
_ctc_asw_datapath_get_unidir_en(uint8 lchip, uint32 gport, uint32* p_enable);
INTERNAL int32
_ctc_asw_datapath_set_pcs_link_isr_en(uint8 lchip, uint32 gport, uint32 enable);
INTERNAL int32
_ctc_asw_datapath_get_pcs_link_isr_en(uint8 lchip, uint32 gport, uint32* p_enable);
INTERNAL int32
_ctc_asw_datapath_get_pcs_type(uint8 lchip, uint32 gport, ctc_chip_serdes_mode_t* p_serdes_mode);
INTERNAL int32
_ctc_asw_datapath_set_pcs_type(uint8 lchip, uint32 gport, ctc_chip_serdes_mode_t serdes_mode);
INTERNAL int32
_ctc_asw_peri_set_phy_prop(uint8 lchip, uint32 gport, uint16 phy_prop_type, void* p_value);
INTERNAL int32
_ctc_asw_peri_get_phy_prop(uint8 lchip, uint32 gport, uint16 phy_prop_type, void* p_value);
INTERNAL int32
_ctc_asw_peri_get_phy_register_exist(uint8 lchip, uint32 gport);
INTERNAL int32
_ctc_asw_peri_get_phy_id(uint8 lchip, uint32 gport, uint32* phy_id);
INTERNAL int32
_ctc_asw_datapath_get_serdes_id(uint8 lchip, uint32 gport, uint8* p_serdes_id);
INTERNAL int32
_ctc_asw_datapath_get_gport_id(uint8 lchip, uint8 sedes_id, uint32* p_gport);
INTERNAL int32
_ctc_asw_chip_get_cpu_port(uint8 lchip);
INTERNAL int32
_ctc_asw_datapath_get_gports(uint8 lchip, uint32* p_gport,uint32* p_cnt);
INTERNAL void
_ctc_asw_chip_phy_link_event_polling_cb(uint8 lchip, uint8 start_idx, uint8 end_idx);
INTERNAL int32
_ctc_asw_chip_check_acl_entry_id(uint8 lchip, uint32 entry_id);
INTERNAL int32
_ctc_asw_chip_get_acl_entry_id(uint8 lchip, uint32* p_entry_id);
INTERNAL int32
_ctc_asw_chip_set_acl_entry_id(uint8 lchip, uint32  entry_id, uint8 enable);
INTERNAL int32 
_ctc_asw_chip_find_entry(uint8 lchip, hw_mac_addr_t        hw_mac, uint16 fid, uint32* entry_id);
INTERNAL int32
_ctc_asw_chip_get_first_slice(uint8 lchip, uint8* p_slice_id);
/**@} end of @defgroup   */

#ifdef __cplusplus
}
#endif

#endif

